红酒质量数据集探索 by Laurence Wu

关于此数据集: 该数据集是关于多种红酒成分和质量的数据集。对于每一种红酒, 该数据集提供了红酒的成分(比如含糖量、pH值等),以及红酒品酒专家给此种红酒品质的 打分。在这份报告中,我将探索这份数据集中不同变量之间的关系。

Univariate Plots Section

## Observations: 1,599
## Variables: 13
## $ X                    <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13...
## $ fixed.acidity        <dbl> 7.4, 7.8, 7.8, 11.2, 7.4, 7.4, 7.9, 7.3, ...
## $ volatile.acidity     <dbl> 0.700, 0.880, 0.760, 0.280, 0.700, 0.660,...
## $ citric.acid          <dbl> 0.00, 0.00, 0.04, 0.56, 0.00, 0.00, 0.06,...
## $ residual.sugar       <dbl> 1.9, 2.6, 2.3, 1.9, 1.9, 1.8, 1.6, 1.2, 2...
## $ chlorides            <dbl> 0.076, 0.098, 0.092, 0.075, 0.076, 0.075,...
## $ free.sulfur.dioxide  <dbl> 11, 25, 15, 17, 11, 13, 15, 15, 9, 17, 15...
## $ total.sulfur.dioxide <dbl> 34, 67, 54, 60, 34, 40, 59, 21, 18, 102, ...
## $ density              <dbl> 0.9978, 0.9968, 0.9970, 0.9980, 0.9978, 0...
## $ pH                   <dbl> 3.51, 3.20, 3.26, 3.16, 3.51, 3.51, 3.30,...
## $ sulphates            <dbl> 0.56, 0.68, 0.65, 0.58, 0.56, 0.56, 0.46,...
## $ alcohol              <dbl> 9.4, 9.8, 9.8, 9.8, 9.4, 9.4, 9.4, 10.0, ...
## $ quality              <int> 5, 5, 5, 6, 5, 5, 5, 7, 7, 5, 5, 5, 5, 5,...

对于该数据集,我看到其中有13个变量,同时有1,599条记录。其中,X变量标识了每一条 不同的记录,和红酒的质量以及其他数据没有任何关系,因此没有统计学上的意义。 在这份报告之后的数据集中,我将去掉这个变量。

##  fixed.acidity   volatile.acidity  citric.acid    residual.sugar  
##  Min.   : 4.60   Min.   :0.1200   Min.   :0.000   Min.   : 0.900  
##  1st Qu.: 7.10   1st Qu.:0.3900   1st Qu.:0.090   1st Qu.: 1.900  
##  Median : 7.90   Median :0.5200   Median :0.260   Median : 2.200  
##  Mean   : 8.32   Mean   :0.5278   Mean   :0.271   Mean   : 2.539  
##  3rd Qu.: 9.20   3rd Qu.:0.6400   3rd Qu.:0.420   3rd Qu.: 2.600  
##  Max.   :15.90   Max.   :1.5800   Max.   :1.000   Max.   :15.500  
##    chlorides       free.sulfur.dioxide total.sulfur.dioxide
##  Min.   :0.01200   Min.   : 1.00       Min.   :  6.00      
##  1st Qu.:0.07000   1st Qu.: 7.00       1st Qu.: 22.00      
##  Median :0.07900   Median :14.00       Median : 38.00      
##  Mean   :0.08747   Mean   :15.87       Mean   : 46.47      
##  3rd Qu.:0.09000   3rd Qu.:21.00       3rd Qu.: 62.00      
##  Max.   :0.61100   Max.   :72.00       Max.   :289.00      
##     density             pH          sulphates         alcohol     
##  Min.   :0.9901   Min.   :2.740   Min.   :0.3300   Min.   : 8.40  
##  1st Qu.:0.9956   1st Qu.:3.210   1st Qu.:0.5500   1st Qu.: 9.50  
##  Median :0.9968   Median :3.310   Median :0.6200   Median :10.20  
##  Mean   :0.9967   Mean   :3.311   Mean   :0.6581   Mean   :10.42  
##  3rd Qu.:0.9978   3rd Qu.:3.400   3rd Qu.:0.7300   3rd Qu.:11.10  
##  Max.   :1.0037   Max.   :4.010   Max.   :2.0000   Max.   :14.90  
##     quality     
##  Min.   :3.000  
##  1st Qu.:5.000  
##  Median :6.000  
##  Mean   :5.636  
##  3rd Qu.:6.000  
##  Max.   :8.000

上图列出了每一个变量的分布。我可以看到,红酒基本都是酸性(最大pH为4.010)。 除了density, pH, alcohol, quality这几个变量之外,其他变量都有outlier。

下面,我会画出每一个变量的histogram,以观察每一个变量的分布。

Univariate Analysis

What is the structure of your dataset?

该数据集包含了12个有统计意义的变量,以及一个用来标识每一条不同记录的ID变量。 我感兴趣的变量主要是12个有统计意义的变量。

What is/are the main feature(s) of interest in your dataset?

对于这份数据集,我对于什么样的成分影响了红酒质量比较感兴趣。因此,我选择了 fixed acidity, volatile acidity, citric acid, residual sugar, chlorides and alcohol这五个变量作为主要研究对象。

What other features in the dataset do you think will help support your investigation into your feature(s) of interest?

对于剩余的变量,free sulfur dioxide, total sulfur dioxide, pH, density and
sulphates,我也会研究他们。我想这对于发现红酒质量受什么样的因素影响也很重要。

Did you create any new variables from existing variables in the dataset?

在这个点上,我目前没有发现需要创建新变量的必要。如果之后有必要 (对探索数据有影响),我会创建新的变量。

Of the features you investigated, were there any unusual distributions? Did you perform any operations on the data to tidy, adjust, or change the form of the data? If so, why did you do this?

数据集中有许多左偏的变量,alcohol, sulphates, total.sulfur.dioxide and free.sulfur.dioxide这些变量的分布均呈现左偏状态。

Bivariate Plots Section

P(2 - 1), 主要研究变量和quality之间的相关性系数(使用Pearson相关性系数)。

P(2 - 2), 其他变量和quality之间的相关性系数(使用Pearson相关性系数)。

P(2 - 3), 除了红酒质量之外,其他所有变量之间的Pearson相关系数。

Bivariate Analysis

Talk about some of the relationships you observed in this part of the investigation. How did the feature(s) of interest vary with other features in the dataset?

就相关性系数表格上看,我只能看到alcohol和quality之间有较大的相关性(0.48)。 而citric.acid和quality也呈现一定的关系,但是不大(0.23)。另外看起来, 其他变量和quality之间似乎没有多大的相关性(相关性系数小于0.3)。

而从P(2 - 3)中可以看到,pH, density and citric.acid这三个变量和fixed.acidity之间 似乎有较强的相关性。

alcohol变量和红酒质量的关系:

P(2 - 4) 酒精含量与红酒质量之间的关系

由此图可以看出,在酒精含量小于13的时候,酒精含量越高,红酒的质量越好。但是在酒精 含量大于13的时候,红酒的质量反而下降了。这也许是由于酒精含量过于大的关系。

探索citric.acid和红酒质量之间的关系。

P(2 - 5) 柠檬酸含量和红酒质量之间的关系

此图可以看出,在柠檬酸含量为0.25 - 0.5之间,和红酒质量有一定的正相关关系。但是 除此之外,并没有非常强的相关性。

Did you observe any interesting relationships between the other features (not the main feature(s) of interest)?

变量free.sulfur.dioxide和total.sulfur.dioxide有较强的相关性。我认为,由于 total.sulfur.dioxide和free.sulfur.dioxide都是同一类化学物质,因此这样的关系也在 清理之中。

What was the strongest relationship you found?

根据三幅相关性变量的图,我主要探索了pH,density和citric.acid这三个变量 同fixed.acidity这个变量之间的关系,我在下面进行了Pearson’s correlation test。

变量pH和fixed.acidity之间的Pearson’s correlation test。

## 
##  Pearson's product-moment correlation
## 
## data:  wine_data$pH and wine_data$fixed.acidity
## t = -37.366, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.7082857 -0.6559174
## sample estimates:
##        cor 
## -0.6829782

变量density和fixed.acidity之间的Pearson’s correlation test。

## 
##  Pearson's product-moment correlation
## 
## data:  wine_data$density and wine_data$fixed.acidity
## t = 35.877, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6399847 0.6943302
## sample estimates:
##       cor 
## 0.6680473

变量citric.acid和fixed.acidity之间的Pearson’s correlation test。

## 
##  Pearson's product-moment correlation
## 
## data:  wine_data$citric.acid and wine_data$fixed.acidity
## t = 36.234, df = 1597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6438839 0.6977493
## sample estimates:
##       cor 
## 0.6717034

从上图中可以看到,pH和fixed.acidity之间的相关性最强,绝对值为0.683。他们实际呈 负线性相关,Pearson’s correlation coefficient为-0.683。

Multivariate Plots Section

P(3 -1) pH, fixed.acidity和citric.acid之间的关系。

P(3 -2) citric, alcohol和quality之间的关系。

Multivariate Analysis

Talk about some of the relationships you observed in this part of the investigation. Were there features that strengthened each other in terms of looking at your feature(s) of interest?

从P(3 - 1)中可以看出,pH和density之间的关联不大,但是density和fixed.acidity 以及pH和fixed.acidity都呈现了负相关的关系。

从P(3 - 2)中可以看出,酒精质量较差的酒大部分集中在图的左下角, 大部分的alcohol < 10,citric.acid < 0.25。同时,从纵轴上看,citric.acid和 酒精质量关系并不大,因为各种质量的点在纵轴上均有分布。不过,确实酒精质量较差的点 在纵轴的底部分布较多。

Were there any interesting or surprising interactions between features?

从P(3 - 1)中可以看出,尽管density和pH之间几乎没有任何相关性,但是数据大部分 集中在图中间部分。由此可以看出,大部分红酒的pH和density几乎都是类似的。

Final Plots and Summary

Plot One

Description One

图一,主要描述了alcohol对于酒精质量的影响。可以看出两者呈现出正相关。

Plot Two

Description Two

图二,描述了除了quality这个Output变量之外,其他自变量的相关性关系。可以看出, pH - fixed.acidity, density - fixed.acidity, citric.acid - fixed.acidity这三组 变量之间的关系最大。

Plot Three

Description Three

图三,描述了alcohol, citric.acid以及factor以后的quality之间的关系。其中可以看出, 大部分高质量的红酒都有较高浓度的柠檬酸(citric.acid)以及酒精(alcohol)。


Reflection

自拿到数据集伊始,我就认为11个input变量中一定有会和quality有很大程度的关系。 没有想到的是,在做双变量分析时,并没有一个变量和红酒质量有强相关性 (pearson相关系数大于0.6),这是一个很大的意外。因此我首先探索了和quality变量 相关性较为明显的alcohol变量。再根据其他变量之间的相关性关系,探索了density, citric.acid, pH和fixed.acidity之间的关系。在下一步中,我希望能进一步探索这四个 变量之间的关系。希望能够建立相关模型,对于新的红酒数据,在知道density, citric.acid和pH之后,能推测出fixed.acidity这个值。